package club.emergency.wechat.authorization.search.consumer.service.fallback_factory;

import club.emergency.wechat.authorization.search.consumer.service.AuthorizationSearchConsumer;
import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.response.StatusCode;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.authorization.search.consumer.service.fallback_factory
 * Date: 2019/3/25
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@Component
public class AuthorizationSearchFallbackFactory implements FallbackFactory<AuthorizationSearchConsumer> {
    @Override
    public AuthorizationSearchConsumer create(Throwable throwable) {

        return new AuthorizationSearchConsumer() {
            @Override
            public String flipListForRole(String roleName, Integer pageNo, Integer pageSize) {
                return ResponseEntity.error(StatusCode.DB_SEARCH_ERROR, "查询角色失败！", throwable.getMessage());
            }

            @Override
            public String flipListAuthorizationByRoleId(Long roleId) {
                return ResponseEntity.error(StatusCode.DB_SEARCH_ERROR, "查询角色对应的权限列表失败！", throwable.getMessage());
            }

            @Override
            public String flipListAuthorizationByCode(Long code, Long parentId) {
                return ResponseEntity.error(StatusCode.DB_SEARCH_ERROR, "根据code查询权限列表失败！", throwable.getMessage());
            }
        };
    }

}
